package com.gitee.wsl.transform.encode.sample

import com.gitee.wsl.transform.encode.EncodeDecode

object ZigzagInteger:EncodeDecode<Int,Int> {
    override fun encode(src: Int): Int {
        return (src shl 1) xor (src shr 31)
    }

    override fun decode(src: Int): Int {
        return (src ushr 1) xor -(src and 1)
    }
}

object ZigzagLong:EncodeDecode<Long,Long> {
    override fun encode(src: Long): Long {
        return (src shl 1) xor (src shr 63)
    }

    override fun decode(src: Long): Long {
        return (src ushr 1) xor -(src and 1)
    }
}